package com.crm.system.controller.sys;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.entity.sys.permissionManagement.SysInvoiceCompany;
import com.crm.model.vo.sys.InvoiceCompanyVO;
import com.crm.model.vo.sys.IssueInvoiceVO;
import com.crm.system.service.sys.InvoiceCompanyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:chaifuyou
 * @Date: 2021/7/23 8:40
 */
@RestController
@RequestMapping("/sysInvoiceCompany")
@Slf4j
public class SysInvoiceCompanyController {

    @Autowired
    private InvoiceCompanyService invoiceCompanyService;

    /**
     * 新增开票公司
     * @param sysInvoiceCompany
     * @return
     */
    @PostMapping("/addInvoiceCompany")
    public DataResponse addCompanyIssueInvoice(@RequestBody SysInvoiceCompany sysInvoiceCompany){
        invoiceCompanyService.addCompanyIssueInvoice(sysInvoiceCompany);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
    }

    /**
     * 根据分公司查询开票公司列表
     * @param companyId
     * @return
     */
    @PostMapping("/selectCompanyInvoiceCompany")
    public DataResponse selectCompanyInvoiceCompany(@RequestParam String companyId){
        List<InvoiceCompanyVO> list= invoiceCompanyService.selectCompanyInvoiceCompany(companyId);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),list);
    }


    /**
     * 查询开票公司列表
     * @param pageIndex
     * @param pageSize
     * @param companyName
     * @return
     */
    @PostMapping("/selectInvoiceCompanyList")
    public DataResponse selectInvoiceCompanyList(@RequestParam(value = "pageIndex", required = false) Integer pageIndex,//页码
                                                 @RequestParam(value = "pageSize", required = false) Integer pageSize,//分页大小
                                                 @RequestParam(value = "companyName", required = false) String companyName,
                                                 @RequestParam(value = "companyStatus", required = false) Integer companyStatus ){
        DhPageInfo<InvoiceCompanyVO> pageVOList = invoiceCompanyService.selectInvoiceCompanyList(pageIndex,pageSize,companyName,companyStatus);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),pageVOList);
    }

    /**
     * 删除开票公司
     * @param companyId
     * @return
     */
    @PostMapping("/delInvoiceCompany")
    public DataResponse delInvoiceCompany(@RequestParam(value = "companyId")String companyId){
        invoiceCompanyService.delInvoiceCompany(companyId);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
    }

    /**
     * 停用开票公司
     * @param companyId
     * @return
     */
    @PostMapping("/stopInvoiceCompany")
    public DataResponse stopInvoiceCompany(@RequestParam(value = "companyId")String companyId,
                                           @RequestParam(value = "type")Integer type){
        invoiceCompanyService.stopInvoiceCompany(companyId,type);
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode());
    }

}
